var TSUI;
(function (TSUI) {
    (function (UI) {
        UI.OpenWindows = 0;
        UI.JustUsedTabKeyTime = 0;
        UI.CurrentFocusedControl = null;
        UI._currTabIndex = 0;

        UI.Global_MouseUpEvent = new TSUI.Events.MouseUpEvent();
        UI.Global_MouseMoveEvent = new TSUI.Events.MouseMoveEvent();

        UI.preventTabKey = false;
        UI.OnKeyDown_Global_First = function (jqEvent) {
            if (jqEvent.keyCode === 9) {
                UI.JustUsedTabKeyTime = Date.now();
            }
            return true;
        };
        UI.OnKeyDown_Global_Last = function (jqEvent) {
            if (jqEvent.keyCode === 9) {
                if (UI.preventTabKey) {
                    UI.preventTabKey = false;
                    TSUI.StopEvent(jqEvent);
                    return false;
                }
            }

            return !jqEvent.isDefaultPrevented();
        };

        var _tapStartTime = Number.MAX_VALUE - 1000;
        var _tapTarget = null;
        if (document.documentElement.hasOwnProperty('ontouchstart')) {
            $(document).on("touchstart", function (event) {
                _tapStartTime = Date.now();
                _tapTarget = $(event.target);
            });
        }

        $(document).on(UI.Control.OnMouseUpEventName, function (event) {
            if (false && _tapStartTime + 10 < Date.now()) {
                _tapTarget = null;
                _tapStartTime = -1;
            } else {
                event = TSUI.standardiseEvent(event);

                UI.Global_MouseUpEvent.Invoke(new TSUI.Events.MouseUpEventArgs(null, event));

                if (!event.isPropagationStopped() && UI.CurrentFocusedControl !== null && !$(event.target).is("input")) {
                    UI.CurrentFocusedControl.Blur();
                }
            }
        });
        $(document).on(UI.Control.OnMouseMoveEventName, function (event) {
             {
                event = TSUI.standardiseEvent(event);
                UI.Global_MouseMoveEvent.Invoke(new TSUI.Events.MouseMoveEventArgs(null, event));
            }
        });

        $(document).on("keyup", function (event) {
            if (!event.isPropagationStopped() && UI.CurrentFocusedControl !== null && event.keyCode === 27) {
                UI.CurrentFocusedControl.Blur();
            }
        });
    })(TSUI.UI || (TSUI.UI = {}));
    var UI = TSUI.UI;
})(TSUI || (TSUI = {}));
$(function () {
    $("body").append("<div class=\"Bg\">");
});
